<?php
defined('RUN_KATANA') or die('Restricted access');
require_once(MODEL_INCLUDE_PATH.'katana/Component.php');
require_once(MODEL_INCLUDE_PATH.'katana/Module.php');
require_once(MODEL_INCLUDE_PATH.'katana/KatanaTheme.php');
require_once(MODEL_INCLUDE_PATH.'global/KatanaText.php');
require_once(MODEL_INCLUDE_PATH.'global/Email.php');
require_once(MODEL_INCLUDE_PATH.'global/Image.php');
require_once(MODEL_INCLUDE_PATH.'global/File.php');
require_once(MODEL_INCLUDE_PATH.'global/Google.php');
require_once(MODEL_INCLUDE_PATH.'global/Pager.php');
$txt 		= new KatanaText();
$com 		= new Component();
$theme 		= new KatanaTheme();
$theme->loadActiveHFB();
if(count($katana->getActiveCores()) > 0)
{
	foreach($katana->ActiveCores as $core) //Load Core Controller Classes
	{
		switch($core->getId())
		{
			case 1 : //Sitemap
				require_once(CONTROLLER_INCLUDE_PATH.$core->getHandle().'/'.$core->getControllerClass().'.php');
			break;
			case 2 : //Access Controller
				require_once(CONTROLLER_INCLUDE_PATH.$core->getHandle().'/'.$core->getControllerClass().'.php');
				$ac			= new $core->ControllerClass();
				$ac->setFrontend(1);
				$user		= new User(0, $txt);
				$userDetails = 0;
			break;
			case 3 : //Form Manager
				require_once(CONTROLLER_INCLUDE_PATH.$core->getHandle().'/'.$core->getControllerClass().'.php');
			break;
			case 6 : //Advertise Controller
				require_once(CONTROLLER_INCLUDE_PATH.$core->getHandle().'/'.$core->getControllerClass().'.php');
			break;
			case 8 : //Shop
				require_once(CONTROLLER_INCLUDE_PATH.$core->getHandle().'/'.$core->getControllerClass().'.php');
			break;
			case 9 : //Survey
				require_once(KATANA_CORES_INCLUDE_PATH.$core->getControllerClass().'.php');
			break;
			case 10 : //Fleet
				require_once(KATANA_CORES_INCLUDE_PATH.$core->getControllerClass().'.php');
			break;
		}
	}
	
	foreach($katana->ActiveCores as $core) //Activate Core Controller Classes
	{
		switch($core->getId())
		{
			case 1 : //Sitemap
				$sitemap	= new $core->ControllerClass();
				$sitemap->setFrontend(1);
				$sitemap->setCoreHandle($core->getHandle());
				$sitemap->frontendActions();
			break;
			case 2 : //Access Controller
				$ac->frontendActions();
				$ac->setCoreHandle($core->getHandle());
			break;
			case 3 : //Form Manager
				$fc			= new $core->ControllerClass();
				$fc->setFrontend(1);
				$fc->setCoreHandle($core->getHandle());
			break;
			case 6 : //Advertise Controller
				$adc		= new $core->ControllerClass();
				$adc->setFrontend(1);
				$adc->setCoreHandle($core->getHandle());
				$adc->frontendActions();
			break;
			case 8 : //Shop
				$shop = new $core->ControllerClass();
				$shop->setFrontend(1);
				$shop->setCoreHandle($core->getHandle());
				if($katana->getProductID() > 0)
				{ 
					$shop->setCurrentProductId($katana->getProductID());
					$shop->loadCurrentProduct();
					$product = $shop->getCurrentProduct();
					if(isset($product))
					{ 
						$katana->setDetailView(true); 
						$katana->setMetaTitle($product->getTitle());
						$katana->addAfterMetaTitle($product->getCatTitle()); //Seo friendly
						$katana->addAfterMetaTitle($product->getGroupTitle()); //Seo friendly
						$katana->addAfterMetaTitle($katana->getTitle());
						
						$katana->setMetaData($katana->getTitle());
						$katana->addBeforeMetaData($product->getGroupTitle());
						$katana->addBeforeMetaData($product->getCatTitle());
						$katana->addBeforeMetaData($product->getTitle());
						
						$katana->setMetaKey($katana->getTitle());
						$katana->addBeforeMetaKey($product->getGroupTitle());
						$katana->addBeforeMetaKey($product->getCatTitle());
						$katana->addBeforeMetaKey($product->getTitle());
					}
					else
					{ 
						$katana->setProductID(0); 
						$katana->setDetailView(false);
					}
				}
				if($katana->getProviderID() > 0)
				{ 
					$shop->setCurrentProviderID($katana->getProviderID());
					if(is_object($shop->getCurrentProvider()))
					{ 
						$katana->setDetailView(true); 
						$katana->setMetaTitle($shop->getCurrentProvider()->getTitle());
						$katana->addAfterMetaTitle($katana->getTitle());
						$katana->setMetaData($katana->getTitle());
						$katana->setMetaKey($katana->getTitle());
					}
					else
					{ 
						$katana->setProviderID(0);
						$shop->setCurrentProviderID(0);
						$katana->setDetailView(false);
					}
				}
				if($katana->getGroupID() > 0)
				{ 
					$shop->setCurrentGroupID($katana->getGroupID());
					if(is_object($shop->getCurrentGroup()))
					{ 
						$katana->setDetailView(true); 
						$katana->setMetaTitle($shop->getCurrentGroup()->getTitle());
						$katana->addAfterMetaTitle($katana->getTitle());
						$katana->setMetaData($katana->getTitle());
						$katana->setMetaKey($katana->getTitle());
					}
					else
					{ 
						$katana->setGroupID(0);
						$shop->setCurrentGroupID(0);
						$katana->setDetailView(false);
					}
				}
				if($katana->getMenuID() > 0)
				{ $shop->setMenuId($katana->getMenuID()); }
				$cart = new Cart($com);
			break;
			case 9 : //Survey
				$surveyCore = new SurveyCore();
				$surveyCore->setCoreHandle($core->getHandle());
			break;
			case 10 : //Fleet
				$fleet = new Fleet(0, $katana->getShipNumber(), 'frontend');
				$fleet->setCoreHandle($core->getHandle());
				if($fleet->getCurrentShipId() > 0)
				{ 
					$katana->setShipId($fleet->getCurrentShipId());
					$katana->setDetailView(true); 
				}
				else
				{ 
					$fleet->loadShipList(); 
					$katana->setDetailView(false);
				}
			break;
		}
	}
}
require(SITE_PATH.'includes/core/hc_loader.php');
/* To be removed */
$result = mysql_query('SELECT value, '.LANG.' FROM '.DB_PERFIX.'words;');
while($row = mysql_fetch_array($result))
{ $word[$row['value']] = $row[LANG]; }
/* To be removed end */
$check 		= new Validator();
$menuclass 	= new Menu();
?>